/*
 * Copyright 2018- The Pixie Authors.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

syntax = "proto3";

package px.carnot.queryresultspb;

option go_package = "queryresultspb";

import "github.com/gogo/protobuf/gogoproto/gogo.proto";
import "google/protobuf/any.proto";
import "src/api/proto/uuidpb/uuid.proto";

// Tracks information about query execution time.
message QueryTimingInfo {
  // The total execution time for the query in nanoseconds.
  int64 execution_time_ns = 1;
  // The time in ns spent compiling the query.
  int64 compilation_time_ns = 2;
}

// QueryExecutionStats contains information about the time/data processed by the
// query.
message QueryExecutionStats {
  QueryTimingInfo timing = 1;
  // The number of input bytes.
  int64 bytes_processed = 2;
  // The number of input records.
  int64 records_processed = 3;
}

message OperatorExecutionStats {
  // The id of the plan fragment containing this operator.
  int64 plan_fragment_id = 1;
  // The id of the operator node within the plan fragment.
  int64 node_id = 2;
  // The number of output bytes.
  int64 bytes_output = 3;
  // The number of output records.
  int64 records_output = 4;
  // The total elapsed time on this operator.
  int64 total_execution_time_ns = 5;
  // The elapsed time of this operator by itself.
  int64 self_execution_time_ns = 6;
  // Any specialied message that an operator might publish.
  // Ie an aggregate operator might want to publish
  google.protobuf.Any operator_stats = 7;
  // Extra metrics to store as a kv.
  map<string, double> extra_metrics = 8;
  // Extra info stored as a string in a map.
  map<string, string> extra_info = 9;
}

message AgentExecutionStats {
  uuidpb.UUID agent_id = 1 [ (gogoproto.customname) = "AgentID" ];
  repeated OperatorExecutionStats operator_execution_stats = 2;
  // The total execution time in nanoseconds for this agent.
  int64 execution_time_ns = 3;
  // The total bytes processed by this agent.
  int64 bytes_processed = 4;
  // The total records processed by this agent.
  int64 records_processed = 5;
}
